package com.hbdl.web.sys.service;

import com.github.pagehelper.PageInfo;
import com.hbdl.common.base.ServiceMybatis;
import com.hbdl.common.mybatis.dao.MybatisDaoUtil;
import com.hbdl.common.utils.ResultUtil;
import com.hbdl.common.utils.TreeUtils;
import com.hbdl.web.sys.model.Ledger;
import com.hbdl.web.sys.model.Resources;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by tanrong.ltr on 16/9/27.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Service
public class LedgerService extends ServiceMybatis<Ledger>  {

    private MybatisDaoUtil<Map> dao = new MybatisDaoUtil<Map>(Map.class);

    /**
     *
     * 分页查询资源
     *
     * @param params
     *
     * @return
     *
     */
    public PageInfo<Map> selectPage(Map params) {

        PageInfo<Map> page = dao.selectPage("LedgerMapper.queryResource", params);
        return page;
    }

    public List<Map> getResourceList(Map params) {
        return dao.selectList("LedgerMapper.queryResource", params);
    }

    public List<Map> getTreeResource(Map params) {
        List list = getResourceList(params);

        List rtList = TreeUtils.toTreeNodeList(list, Resources.class);

        ResultUtil.getSuccessResult(rtList);

        return rtList;
    }

    public List<Map> getResourceByUser(Map params) {
        return dao.selectList("LedgerMapper.getResourceByUser", params);
    }

}
